//
//  MeViewController.m
//  UI-21-豆豆豆瓣
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 Wang Hao. All rights reserved.
//

#import "MeViewController.h"
#import "CollectionViewController.h"
#import "MovieListViewController.h"


@interface MeViewController ()

@property (nonatomic, retain) MovieListViewController *movie1;;
@property (nonatomic ,retain) CollectionViewController *movie2;
@property (nonatomic, assign) BOOL isSelectd;

@end

@implementation MeViewController

- (void)dealloc
{
    [_movie1 release];
    [_movie2 release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"电影";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav@2x"] forBarMetrics:UIBarMetricsDefault];
    // Do any additional setup after loading the view.
    //自定义系统按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 30, 30);
    [button setBackgroundImage:[UIImage imageNamed:@"btn_nav_list@2x"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"btn_nav_collection@2x"] forState:UIControlStateSelected];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

    self.movie1 = [[MovieListViewController alloc] init];
    self.movie2 = [[CollectionViewController alloc] init];
    [self addChildViewController:self.movie1];
    [self addChildViewController:self.movie2];
    [self.view addSubview:self.movie1.view];
    [self.view addSubview:self.movie2.view];
    [_movie2 release];
    [_movie1 release];
    self.isSelectd = NO;
    
    
}

-(void)buttonAction:(UIButton *)but{
    
    if (self.isSelectd == NO) {
        
        [UIView transitionFromView:self.movie2.view toView:self.movie1.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
            
            
        }];
    }else{
        
        [UIView transitionFromView:self.movie1.view toView:self.movie2.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
            
        }];
    }
    self.isSelectd = !self.isSelectd;
    but.selected = !but.selected;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
